package io.gitee.sfch.chunmi.controller.system;

import io.gitee.sfch.chunmi.entity.Pageable;
import io.gitee.sfch.chunmi.entity.Pagination;
import io.gitee.sfch.chunmi.entity.Response;
import io.gitee.sfch.chunmi.controller.system.form.SystemProductAddForm;
import io.gitee.sfch.chunmi.dao.system.entity.SystemProduct;
import io.gitee.sfch.chunmi.service.system.SystemProductService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统产品
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/system/product")
public class SystemProductController {

    @Resource
    private SystemProductService systemProductService;

    /**
     * 分页查询
     */
    @GetMapping("/findPage")
    public Response<Pagination<SystemProduct>> findPage(SystemProduct request, Pageable pageable) {
        Pagination<SystemProduct> page = systemProductService.findPage(request, pageable);
        return Response.success(page);
    }

    /**
     * 新增产品
     */
    @PostMapping("/add")
    public Response<String> addProduct(@RequestBody @Valid SystemProductAddForm command) {
        systemProductService.addProduct(command);
        return Response.successEmpty(null);
    }
}
